package com.warm.calc.demo.service;

import com.warm.calc.demo.entity.CalcCompleteData;
import com.warm.calc.demo.entity.CalcKeyword;
import com.warm.calc.demo.entity.CalcSourceData;
import com.warm.calc.demo.entity.CalcType;
import com.warm.calc.demo.service.parser.AttributeHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.ArrayList;
import java.util.List;

@Service
public class CalcService {

    @Autowired
    private AttributeHandler attributeHandler;

    public boolean exportData(Object data){
        // 解析excel，获取原始数据
        List<CalcSourceData> exportData = new ArrayList<>();
        // 保存数据库 todo

        // 提取数据
        parseData(exportData);
        return true;
    }


    public boolean parseData(List<CalcSourceData> sources){
        // 查询关键字配置
        List<CalcKeyword> keywords = new ArrayList<>();
        // 查询属性配置
        List<CalcType> types = new ArrayList<>();
        // 通过原始数据，提取数据
        List<CalcCompleteData> targets = new ArrayList<>();
        sources.forEach(source -> {
            CalcCompleteData target = new CalcCompleteData();
            attributeHandler.parser(source, target, keywords, types);
            targets.add(target);
        });
        // 保存提取后的数据到数据库 todo

        return true;
    }
}
